import sqlite3
from json_operate import get_ph_en
from spider import get_pronounce
import _thread
def get_spelling(id):
    coon = sqlite3.connect("../helloword.db")
    cursor = coon.cursor()
    cursor.execute('select spelling from word where wid={}'.format(id))
    return cursor.fetchone()[0]



def update_pronounce(startid,endid):
    coon = sqlite3.connect("../helloword.db")
    cursor = coon.cursor()
    sql = ''' UPDATE word
              SET pronounce = ? 
              WHERE id = ?'''

    for i in range(startid,endid):
        spelling = get_spelling(i)
        cursor.execute(sql,(get_pronounce(spelling),i))
        print("%f"%(i/103477),end='',flush=True)
    coon.commit()
    coon.close()





if __name__ == '__main__':
    # for i in range(4, 20):
    #      update_pronounce((i-1)*5000+1,i*5000)
    update_pronounce(103477 + 1, 103976)




    # try:
    #     for i in range(1,20):
    #         _thread.start_new_thread(update_pronounce((i-1)*5000+1,i*5000))
    #     _thread.start_new_thread(update_pronounce(100001, i * 103477))
    # except:
    #     print("error")
